<template>
  <div class="menu-wrapper">
    <el-form ref="brandForm" :model="form"  label-width="80px">
      <div style="width: 100%;display: flex;align-items: flex-end;border-bottom: 1px #eee solid;margin-bottom: 20px" >
        <span style="font-size: 18px;color:#409EFF;margin: 10px 0;">基本信息</span>
      </div>
      <el-form-item label="银行编号" prop="code" :rules="{ required: true, message: '请输入银行编号', trigger: 'blur' }">
        <el-col :span="5">
          <el-input v-model="form.code"/>
        </el-col>
      </el-form-item>
   
      <el-form-item label="银行名称">
        <el-col :span="5">
          <el-input  v-model="form.name"/>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-col :span="12">
          <el-button type="primary"  :loading="clicked" @click="saveBank('brandForm')">
            &nbsp&nbsp&nbsp&nbsp完 成&nbsp&nbsp&nbsp&nbsp
          </el-button>
        </el-col>
      </el-form-item>
    </el-form>

  </div>
</template>
<style scoped>
  .menu-wrapper{
    margin: 15px;
  }
</style>
<script>
  import { EventBus } from '@/api/eventBus'
  import utils from '../../utils/utils.js'
  import { save } from '@/api/bank'
  import SingleUpload from '@/components/Upload/singleUpload'
  export default {
    name:'bank-add',
    filters: {

    },
    components: {
      SingleUpload
    },

    data() {
      return {
        clicked: false, // 按钮防双击
        form: {
          code: '',
          name:''
        },
        singleUploadTitle:'100*100'
      }
    },
    created() {

    },
     watch: {
    // 路由地址不变的情况下,如果id变化则重新获取数据
    $route(newVal, oldVal) {
      console.log(newVal);
      if (newVal.name == "bank-add" && newVal.query.id != this.id) {
        this.getData();
      }
    },
  },
    methods: {
      saveBank(form) {
        
        const _this = this
        this.$refs[form].validate((valid) => {
          if (valid) { // 校验表单
            _this.clicked = true
            save(_this.form).then(response => {
              console.log(_this.form);
              console.log(response)
              _this.clicked = false
                EventBus.$emit('bank-add', response.data)
                _this.$store.dispatch('tagsView/delView', _this.$route).then(({ visitedViews }) => {
                  _this.$router.push({
                    path: '/bank/list'
                  })
                })// 关闭当前tab回到列表
            }).catch(error => {
              _this.clicked = false

            })
          } else {
            return false
          }
        })
      }
    }
  }
</script>
